from typing import List

from tortoise import models
from tortoise import fields


class AbstractBaseModel(models.Model):
    """基础模型类"""
    created = fields.DatetimeField(null=True, auto_now_add=True)
    modified = fields.DatetimeField(null=True, auto_now=True)

    class Meta:
        abstract = True


class Dao:

    def __init__(self, model: models.Model):
        self.model = model

    async def get(self, **kwargs):
        """返回一个对象"""
        result = getattr(self.model, 'get')(**kwargs)
        return await result.values()

    async def create(self, schema=None):
        """ 创建 """
        result = await getattr(self.model, 'create')(**schema.dict(exclude_unset=True))
        return result
